package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityInquirySuccessBinding;
import com.sgb.kjwl.view.constant.RouterKey;
import com.swgk.core.dialog.RoundDialog;

/**
 * @author: 杨畔
 * @date: 2021/2/6 15:50
 * @Description: 询价成功页面
 */
public class InquirySuccessActivity extends AppActivity {

    ActivityInquirySuccessBinding mBinding;
    //询价no和司机电话
    private String mNo;
    private String mPhone;

    public static void start(Context context, String no, String phone) {
        Intent intent = new Intent(context, InquirySuccessActivity.class);
        intent.putExtra(RouterKey.NO, no);
        intent.putExtra(RouterKey.STRING, phone);
        context.startActivity(intent);
    }

    @Override
    protected void init() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_inquiry_success);
        mBinding.setLifecycleOwner(this);
        mBinding.includeTitle.titleView.setText("询价结果");
        mBinding.includeTitle.ivBack.setOnClickListener(this);
        mBinding.setOnClick(this);
        //获取数据
        mNo = getIntent().getStringExtra(RouterKey.NO);
        mPhone = getIntent().getStringExtra(RouterKey.STRING);
    }

    @Override
    public void onClick(View v) {
        if (v == mBinding.includeTitle.ivBack) {
            finish();
        } else if (v == mBinding.tvInquirySuccessDetail) {
            //todo 询价详情
            InquiryDetailActivity.start(this,true,mNo);
            finish();
        } else if (v == mBinding.tvInquirySuccessContact) {
            if (!TextUtils.isEmpty(mPhone)) {
                showCallDialog();
            }
        }
    }

    /**
     * 联系车主
     */
    private void showCallDialog() {
        new RoundDialog.Builder(this)
                .title("确认呼叫")
                .confirm("确定")
                .cancel("取消")
                .content(mPhone)
                .cancelable(true)
                .confirmCallback(v -> callPhone(mPhone))
                .show();
    }
}
